import React, { Component } from 'react';
import {Switch,Route,Redirect} from 'react-router-dom';
export default class RouterView extends Component {
    render() {
        let {routes} =this.props;
        let compList =routes.filter((v)=>v.path);
        let redirList =routes.filter((v)=>v.to);
       
        
        return (
            <Switch>
                 {compList.map((v,i)=>{
                    return <Route path={v.path} key={i} render={(props)=>{
                        if(v.meta && v.meta.needLogin && !sessionStorage.getItem('token')){
                            return <Redirect from={v.path} to="/login" ></Redirect>
                        }else{
                            return <v.component routes={v.children || [] } {...props}> </v.component>
                        }
                      
                    }}></Route>
                })}

               {redirList.map((v,i)=>{
                   return <Redirect from={v.from} to={v.to} key={i}></Redirect>
               })}
              
            </Switch>
        )
    }
}
